package com.kkb.controller;

import com.kkb.bean.Eadmit;
import com.kkb.service.AdmitService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@Controller
public class LoginController {
    @Resource
    private AdmitService admitService;
    @RequestMapping("/login")
    public String login(){
        return "logins";
    }
    @RequestMapping("/getAdmit")
    public String logins(String username, String password, HttpServletResponse response){
        Eadmit admit = admitService.findAdmit(username,password);
        response.setContentType("text/html;charset=utf-8");
        if (admit!=null){
            return "success";
        }else{
            try (PrintWriter writer = response.getWriter()) {
                writer.print("<script>alert('账号或密码输入错误'); location.href='logins.jsp'>");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
